#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>

#include "scull_app.h"

#define SCULLDEV "/dev/scull0"
int main(void)
{
	int fd;
	unsigned long len;

	int quantum = 3000, qset = 20;

	fd = open(SCULLDEV, O_RDWR);
	if (fd == -1) {
		printf("open err! %m\n");
		exit(-1);
	}
	printf("open %s success! fd = %d\n", SCULLDEV, fd);

	printf("0--SCULL_IOCRESET\n");
	ioctl(fd, SCULL_IOCRESET, &quantum);
	
	printf("1--SCULL_IOCSQUANTUM<--quantum = %d\n", quantum);
	ioctl(fd, SCULL_IOCSQUANTUM, &quantum);

	quantum = 2500;
	ioctl(fd, SCULL_IOCTQUANTUM, quantum);
	printf("2--SCULL_IOCTQUANTUM -->quantum = %d\n", quantum);

	ioctl(fd, SCULL_IOCGQUANTUM, &quantum);
	printf("3--SCULL_IOCGQUANTUM -->quantum = %d\n", quantum);

	quantum = ioctl(fd, SCULL_IOCQQUANTUM);
	printf("4--SCULL_IOCQQUANTUM -->quantum = %d\n", quantum);

	quantum = 5000;
	printf("5--quantum = %d-->", quantum);
	ioctl(fd, SCULL_IOCXQUANTUM, &quantum);
	printf("SCULL_IOCXQUANTUM -->old quantum = %d\n", quantum);

	quantum = 600;
	printf("6--quantum = %d-->", quantum);
	quantum = ioctl(fd, SCULL_IOCHQUANTUM, quantum);
	printf("SCULL_IOCHQUANTUM -->old quantum = %d\n", quantum);


	printf("7--SCULL_IOCSQSET <--qset = %d\n", qset);
	ioctl(fd, SCULL_IOCSQSET, &qset);

	qset = 40;
	printf("8--SCULL_IOCTQSET <--qset = %d\n", qset);
	ioctl(fd, SCULL_IOCTQSET, qset);

	ioctl(fd, SCULL_IOCGQSET, &qset);
	printf("9--SCULL_IOCGQSET -->qset = %d\n", qset);

	qset = ioctl(fd, SCULL_IOCQQSET);
	printf("10--SCULL_IOCQQSET -->qset = %d\n", qset);

	qset = 20;
	printf("11--qset = %d-->", qset);
	ioctl(fd, SCULL_IOCXQSET, &qset);
	printf("SCULL_IOCXQSET -->old qset = %d\n", qset);

	qset = 30;
	printf("12--qset = %d-->", qset);
	qset = ioctl(fd, SCULL_IOCHQSET, qset);
	printf("SCULL_IOCHQSET -->old qset = %d\n", qset);

	close(fd);
	
	return 0;
}
